package com.tongji.showroom.command
{ 	
	import com.tongji.showroom.events.AddUserProductEvent;
	import com.tongji.showroom.model.PictureModel;
	import com.tongji.showroom.service.UserProductService;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	
	import org.robotlegs.mvcs.Command;
	
	/**
	 * 
	 * @author jiarong
	 * 
	 */
	public class AddUserProductCommand extends Command
	{
		[Inject]
		public var service:UserProductService;
		
		[Inject]
		public var model:PictureModel;
		
		[Inject]
		public var event:AddUserProductEvent;
		
		public function AddUserProductCommand()
		{
			super();
		}
		
		override public function execute():void
		{
			switch (event.type)
			{
				case AddUserProductEvent.ADD_USER_PRODUCT:
					if (event.imgUrlList != null)
						service.addUserProduct(event.userId, event.imgUrlList as Array);
					break;
				case AddUserProductEvent.GET_USER_PRODUCT:
					service.getUserProduct(event.userId);
					break;
				case AddUserProductEvent.UPDATE_USER_MODEL:
					model.updatePicture(event.str);
					break;
				case AddUserProductEvent.DELETE_USER_PRODUCT:
					if (event.imgUrlList != null)
						service.deleteProductById(event.imgId);
					break;
				case AddUserProductEvent.DELETE_A_PICTURE:
					model.deletePic(event.imgId);
					break;
				default:
					break;
			}	
		}
	}
}